package com.itheima.mapper;

import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface EmpMapper {

/*   传统方式实现分页
  //获取总记录数目
    @Select("select count(*) from emp")
    long count();

    //获取当前页的结果列表
    @Select("select * from emp limit #{start},#{pageSize}")
    List<Emp> list(Integer start, Integer pageSize);*/

    //使用PageHelper插件实现分页
//    @Select("select * from emp")
    Page<Emp> list(String name, Short gender, LocalDate begin, LocalDate end);

    //删除员工
    void delete(List<Integer> ids);

    //添加员工
    @Insert("insert into emp ( username,  name, gender,  job, dept_id, entrydate, create_time, update_time )" +
            "values (#{username},#{name},#{gender},#{job},#{deptId},#{entrydate}, #{createTime}, #{updateTime})")
    void add(Emp emp);

    //根据ID查询员工信息
    @Select("select id, username, password, name, gender, image, job, entrydate, dept_id, create_time, update_time " +
            "from emp " +
            "where id = #{id}")
    Emp findById(Number id);

    void update(Emp emp);

    //登录验证
    @Select("select * from emp where username = #{username} and password=#{password}")
    Emp findUser(Emp emp);

    //删除部门下的所有员工信息
    @Delete("delete from emp where dept_id = #{deptId}")
    void deleteByDeptId(Integer deptId);
}
